const path = require("path");
const HtmlPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

const htmlPlugin = new HtmlPlugin({
  template: "./src/index.html",
  filename: "./index.html",
});

const cleanWebpackPlugin = new CleanWebpackPlugin();

module.exports = {
  mode: "development",
  devtool: "nosources-source-map",
  plugins: [htmlPlugin, cleanWebpackPlugin],
  entry: path.join(__dirname, "./src/index.js"),
  output: {
    path: path.join(__dirname, "./dist"),
    filename: "js/bundle.js",
  },
  devServer: {
    open: true,
    host: "127.0.0.1",
    port: 80,
  },
  module: {
    rules: [
      {
        test: /\.(c|le)ss$/,
        use: ["style-loader", "css-loader", "less-loader"],
      },
      {
        test: /\.(jpg|png|gif)$/,
        use: ["url-loader?limit=5000&outputPath=images"],
      },
      {
        test: /\.js$/,
        use: "babel-loader",
        exclude: /node_modules/,
      },
    ],
  },
};
